<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html [
    <!ENTITY nbsp "&#160;">
    <!ENTITY uarr "&#8593;">
    <!ENTITY darr "&#8595;">
]>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:tn="http://tamalnath.appspot.com/functions">

    <ui:composition template="/WEB-INF/content/layout.xhtml">

        <ui:define name="meta">
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
        </ui:define>

        <ui:define name="title">${msg['menu.email.read']}</ui:define>

        <ui:define name="style">
        <style>
.column {
    max-width: 6em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
        </style>
        </ui:define>
        <ui:define name="content">

<h:form id="form">

    <h:messages />

    <h:dataTable id="dataTable" value="#{entity.entities}" var="email" rowClasses="odd,even" columnClasses="column,column">
        <h:column rowHeader="#{entity.order eq 'from'}">
            <f:facet name="header">
                <h:commandLink id="from" value="${msg['email.from']}" actionListener="#{entity.processAction}" />
                <h:outputText rendered="#{entity.order eq 'from'}" value="${entity.desc ? '&uarr;' : '&darr;'}" />
            </f:facet>
            <ui:repeat value="#{email.properties['from']}" var="v">
                <h:outputText value="#{tn:emailPersonal(v)}" />
                <br/>
                <h:outputText value="#{tn:emailAddress(v)}" />
            </ui:repeat>
        </h:column>
        <h:column rowHeader="#{entity.order eq 'subject'}">
            <f:facet name="header">
                <h:commandLink id="subject" value="${msg['email.subject']}" actionListener="#{entity.processAction}" />
                <h:outputText rendered="#{entity.order eq 'subject'}" value="${entity.desc ? '&uarr;' : '&darr;'}" />
            </f:facet>
            <h:outputText value="#{email.properties['subject']}" />
        </h:column>
        <h:column rowHeader="#{entity.order eq 'receivedDate'}">
            <f:facet name="header">
                <h:commandLink id="receivedDate" value="${msg['email.receivedDate']}" actionListener="#{entity.processAction}" />
                <h:outputText rendered="#{entity.order eq 'receivedDate'}" value="${entity.desc ? '&uarr;' : '&darr;'}" />
            </f:facet>
            <h:outputText styleClass="fromNow" value="#{email.properties['receivedDate']}" >
                <f:convertDateTime timeZone="${sessionScope.TIMEZONE}" pattern="EEE MMM dd yyyy HH:mm:ss 'GMT'Z (z)" />
            </h:outputText>
        </h:column>
        <h:column>
            <a href="#detail#{email.key.name}" data-rel="popup" data-role="button" data-transition="pop" data-iconpos="notext" data-icon="info">detail</a>

            <article data-role="popup" id="detail#{email.key.name}">
            <header data-role="header" data-theme="a">
                <h3><h:outputText value="#{msg['menu.email.read']}" /></h3>
                <a href="#" data-role="button" data-rel="back" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Back</a>
            </header>
            <section data-role="content" style="word-wrap:break-word;">
            <dl>
                <dt><h:outputText rendered="#{email.properties['from'] ne null}" value="${msg['email.from']}" /></dt>
                <dd>
                    <ui:repeat value="#{email.properties['from']}" var="v">
                        <h:outputText value="#{v}" /><br />
                    </ui:repeat>
                </dd>
                <dt><h:outputText rendered="#{email.properties['to'] ne null}" value="${msg['email.to']}" /></dt>
                <dd>
                    <ui:repeat value="#{email.properties['to']}" var="v">
                        <h:outputText value="#{v}" /><br />
                    </ui:repeat>
                </dd>
                <dt><h:outputText rendered="#{email.properties['cc'] ne null}" value="${msg['email.cc']}" /></dt>
                <dd>
                    <ui:repeat value="#{email.properties['cc']}" var="v">
                        <h:outputText value="#{v}" /><br />
                    </ui:repeat>
                </dd>
                <dt><h:outputText rendered="#{email.properties['bcc'] ne null}" value="${msg['email.bcc']}" /></dt>
                <dd>
                    <ui:repeat value="#{email.properties['bcc']}" var="v">
                        <h:outputText value="#{v}" /><br />
                    </ui:repeat>
                </dd>
                <dt><h:outputText rendered="#{email.properties['sender'] ne null}" value="${msg['email.sender']}" /></dt>
                <dd><h:outputText rendered="#{email.properties['sender'] ne null}" value="#{email.properties['sender']}" /></dd>
                <dt><h:outputText value="${msg['email.sentDate']}" /></dt>
                <dd><time><h:outputText value="#{email.properties['sentDate']}" /></time></dd>
                <dt><h:outputText value="${msg['email.receivedDate']}" /></dt>
                <dd><time><h:outputText value="#{email.properties['receivedDate']}" /></time></dd>
                <dt><h:outputText value="${msg['email.subject']}" /></dt>
                <dd><h:outputText value="#{email.properties['subject']}" /></dd>
                <dt><h:outputText value="${msg['email.body']}" /></dt>
                <dd><pre><h:outputText value="#{email.properties['body'].value}" /></pre></dd>
            </dl>
            </section>
            </article>
        </h:column>
        <h:column>
            <a href="#delete#{email.key.name}" data-rel="popup" data-role="button" data-transition="pop" data-iconpos="notext" data-icon="delete">delete</a>
            <article data-role="popup" id="delete#{email.key.name}">
            <header data-role="header" data-theme="a">
                <h3><h:outputText value="#{msg['delete']}" /></h3>
            </header>
            <section data-role="content">
                <p><h:outputText value="${msg['entity.message.delete']}" /></p>
                <a href="#" data-role="button" data-inline="true" data-rel="back">${msg['cancel']}</a>
                <h:commandLink id="delete" value="${msg['delete']}" actionListener="#{entity.processAction}">
                    <f:passThroughAttribute name="data-role" value="button" />
                    <f:passThroughAttribute name="data-inline" value="true" />
                    <f:passThroughAttribute name="data-rel" value="back" />
                    <f:attribute name="name" value="#{email.key.name}" />
                </h:commandLink>
            </section>
            </article>
        </h:column>

        <f:facet name="footer">
        <p style="text-align: center; margin: 0em;">
            <h:outputFormat value="#{msg['page.pageinfo']}">
                <f:param value="#{entity.first}" />
                <f:param value="#{entity.last}" />
                <f:param value="#{entity.count}" />
            </h:outputFormat>
            <br />
            <h:commandLink actionListener="#{entity.processAction}" id="first"    value="${msg['page.first']}"    disabled="#{entity.page eq 0}" />
            &nbsp;
            <h:commandLink actionListener="#{entity.processAction}" id="previous" value="${msg['page.previous']}" disabled="#{entity.page eq 0}" />
            &nbsp;
            <h:commandLink actionListener="#{entity.processAction}" id="next"     value="${msg['page.next']}"     disabled="#{entity.last eq entity.count}" />
            &nbsp;
            <h:commandLink actionListener="#{entity.processAction}" id="last"     value="${msg['page.last']}"     disabled="#{entity.last eq entity.count}" />
        </p>
        </f:facet>
    </h:dataTable>

</h:form>

        </ui:define>
    </ui:composition>

</html>